package jdbc;

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestOracle {

    private static String URL = "jdbc:oracle:thin:@//192.168.228.130:1521/orcl";

    private static String USERNAME = "sys as sysdba";

    private static String PASSWORD = "lzj";

    @Test
    public void testConn() {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            System.out.println(conn);
            PreparedStatement stat = conn.prepareStatement("SELECT * FROM dba_users");
            ResultSet resultSet = stat.executeQuery();
            while (resultSet.next()) {
                String username = resultSet.getString("username");
                System.out.println(username);
            }
        }
        catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }

    }
}



